package com.itheima.controller;

import com.itheima.pojo.*;
import com.itheima.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Slf4j
@RestController
public class ClazzController {
    @Autowired
    private ClazzService clazzService;
    @GetMapping("/clazzs")
    public Result findAll(ClazzQueryParam clazzQueryParam){
        log.info("分页查询，参数：{}",clazzQueryParam);
        PageBean pageBean = clazzService.page(clazzQueryParam);
        return Result.success(pageBean);

    }
    @PostMapping("/clazzs")
    public Result add( @RequestBody Clazz clazz){
        log.info("添加班级，参数：{}",clazz);
        clazzService.add(clazz);
        return Result.success();
    }
    @PutMapping("/clazzs")
    public Result update(@RequestBody Clazz clazz){
        log.info("修改班级信息：{}",clazz);
        clazzService.update(clazz);
        return Result.success();
    }
    @GetMapping("/clazzs/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("根据id查询班级信息：{}",id);
        Clazz clazz = clazzService.findById(id);
        return Result.success(clazz);
    }
    @DeleteMapping("/clazzs/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("根据id删除班级信息：{}",id);
        clazzService.delete(id);
        return Result.success();
    }
    @GetMapping("/clazzs/list")
    public Result findAll(){
        log.info("查询全部班级信息");
        List<Clazz> clazzList = clazzService.findAll();
        return Result.success(clazzList);
    }



}
